package com.zjuh.taofood.biz.dao.ibatis;

import java.util.List;
import java.util.Map;

import wint.lang.utils.MapUtil;

import com.zjuh.taofood.biz.dao.ActiveTopicItemDAO;
import com.zjuh.taofood.biz.dao.query.ActiveTopicItemQuery;
import com.zjuh.taofood.biz.domain.ActiveTopicItemDO;

public class ActiveTopicItemDAOIbatis extends BaseIbatisDAO implements ActiveTopicItemDAO  {

	@Override
	public void deleteByTopicId(long topicId) {
		this.getSqlMapClientTemplate().update("ActiveTopicItemDAO.deleteByTopicId", topicId);
	}

	public long create(ActiveTopicItemDO activeTopicItem) {
		return (Long)this.getSqlMapClientTemplate().insert("ActiveTopicItemDAO.create", activeTopicItem);
	}

	public void delete(long id) {
		this.getSqlMapClientTemplate().update("ActiveTopicItemDAO.delete", id);
	}

	public void update(ActiveTopicItemDO activeTopicItem) {
		this.getSqlMapClientTemplate().update("ActiveTopicItemDAO.update", activeTopicItem);
	}

	public ActiveTopicItemDO queryById(long id) {
		return (ActiveTopicItemDO)this.getSqlMapClientTemplate().queryForObject("ActiveTopicItemDAO.queryById", id);
	}

	public int queryCountByTopicId(long topicId) {
		return (Integer)this.getSqlMapClientTemplate().queryForObject("ActiveTopicItemDAO.queryCountByTopicId", topicId);
	}
	
	@Override
	public ActiveTopicItemDO queryByItemIdAndTopicId(long itemId, long topicId) {
		Map<String, Object> params = MapUtil.newHashMap();
		params.put("itemId", itemId);
		params.put("topicId", topicId);
 		return (ActiveTopicItemDO)this.getSqlMapClientTemplate().queryForObject("ActiveTopicItemDAO.queryByItemIdAndTopicId", params);
	}
	
	@SuppressWarnings("unchecked")
	public List<ActiveTopicItemDO> queryByItemId(long itemId) {
		return (List<ActiveTopicItemDO>)this.getSqlMapClientTemplate().queryForList("ActiveTopicItemDAO.queryByItemId", itemId);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ActiveTopicItemDO> queryByTopicId(ActiveTopicItemQuery activeTopicItemQuery) {
		int count = (Integer)this.getSqlMapClientTemplate().queryForObject("ActiveTopicItemDAO.queryByTopicIdCount", activeTopicItemQuery);
		activeTopicItemQuery.setTotalResultCount(count);
		return (List<ActiveTopicItemDO>)this.getSqlMapClientTemplate().queryForList("ActiveTopicItemDAO.queryByTopicId", activeTopicItemQuery);
	}

	
}
